package com.anytrek.demowebclient.controller;

import com.anytrek.demowebclient.api.ApiService;
import com.anytrek.demowebclient.entity.UserEntity;
import com.anytrek.demowebclient.utils.ApiResult;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import javax.xml.transform.stax.StAXResult;

@Log4j2
@RestController
@RequestMapping("/api")
public class ApiController {

    private final ApiService apiService;

    @Autowired
    public ApiController(ApiService apiService) {
        this.apiService = apiService;
    }

    //http://localhost:8080/api/1
    @GetMapping("{id}")
    public Mono<ApiResult> getParamApi(@PathVariable("id") Integer id) {
        return apiService.getParamApi(id);
    }

    //http://localhost:8080/api/admin
    @PostMapping("{name}")
    public Mono<ApiResult> postParamApi(@PathVariable("name") String name) {
        return apiService.postParamApi(name);
    }

    //http://localhost:8080/api/restful/1
    @GetMapping("/restful/{id}")
    public Mono<ApiResult> getRestFulApi(@PathVariable("id") Integer id) {
        return apiService.getRestFulApi(id);
    }

    //http://localhost:8080/api/update  +   body
    @PostMapping("/update")
    public Mono<ApiResult> postBodyApi(@RequestBody UserEntity userEntity) {
        return apiService.postBodyApi(userEntity);
    }
}